package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.ActionEffect.Value;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 坚不可摧<br/>
 * 六百年无人能超越的厚脸皮为己方全体成员增加一个等同于自身气势值{0=300#0}%的护盾，持续{1=5#0}回合或被击破为止
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90102 extends CombatSkill {

	public COMBAT_SKILL_90102(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		List<CombatUnit> units = action.unit.getTeam().all();
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				// hp
				action.addBuff(new BUFF(skill, unit));
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		int hp;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner, (int) skill.getParameter(1));
			this.hp = (int) (owner.getHp() * skill.getParameter(0) / GameStaticConfig.percentBase);
		}
		@Override
		public void preDamage(ActionEffect effect) {
			active = true;
			int delta = effect.getHpDelta();
			if (delta < 0 && hp > 0) {
				hp += delta;
				Value v = effect.getValue(CombatAttributeType.HP);
				v.setDelta(hp > 0 ? 0 : hp);
			}
		}
		@Override
		public void roundEnd(Round round) {
			super.roundEnd(round);
			if (state != STATE_REMOVED && hp <= 0) { // 破盾
				uneffect();
				round.addBuff(this);
			}
		}
	}

}
